package com.ponxu.mb.web.action;

import java.io.IOException;

import javax.servlet.ServletException;

import com.ponxu.log.Log;
import com.ponxu.log.LogFactory;
import com.ponxu.mb.model.Post;
import com.ponxu.mb.service.PostService;
import com.ponxu.utils.Lang;
import com.ponxu.web.core.WebContext;

/**
 * 页面
 * 
 * @author xwz
 * 
 */
public class PageServlet extends MiniBlogAction {
	private static final Log LOG = LogFactory.getLog();
	private static final String FTL_PAGE = "page.ftl";

	public String execute(WebContext context) throws ServletException,
			IOException {
		int id = context.getIntParameter("id");
		String seoTitle = context.getParameter("seotitle");
		LOG.debug("id=%d, seotitle=%s", id, seoTitle);

		Post post = null;
		if (id != 0) {
			post = PostService.getById(id);
		} else if (Lang.isNotEmpty(seoTitle)) {
			post = PostService.getBySeoTitle(seoTitle);
		}

		if (post == null) {
			return FTL_404;
		}

		context.put("post", post);
		return FTL_PAGE;
	}

}
